package com.MyDemo.demo.aspect;

import org.aspectj.lang.annotation.*;


import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.util.StopWatch;

@Aspect
@Component
public class AspectTest {

    Logger logger = LoggerFactory.getLogger("com.sentinel.demo.aspect");


    @Around("methodsToBeProfiled()")
    public Object profile(ProceedingJoinPoint pjp) throws Throwable {
        StopWatch sw = new StopWatch(getClass().getSimpleName());
        try {
            sw.start(pjp.getSignature().getName());
            return pjp.proceed();
        } finally {
            sw.stop();
            logger.info(sw.prettyPrint());
        }
    }


    @Pointcut("execution(public * com.MyDemo.demo.controller.ControllerDemo.*(..))")
    public void methodsToBeProfiled() {
    }
}